package com.jnmd.video.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jnmd.video.service.AdminService;
import com.jnmd.video.utils.Md5Utils;

@Controller
@RequestMapping("admin")
public class LoginController {
	@Autowired
    AdminService adminService;
	
	@RequestMapping("showLogin")
	public String show(){
		return "admin/login";
	}
	@RequestMapping("adminLogin")
	public String show2(String username,String password,HttpSession sessison){
		
		password=Md5Utils.md5(password);
		sessison.setAttribute("username", username);
        int result =adminService.login(username, password);
		if(result>0){
			
			sessison.setAttribute("username", username);
			return "redirect:/video/showVideo.action";
		}
		return "admin/login";
	}
	
	@RequestMapping("logout")
	public String show3(HttpSession sessison){
		if(null!=sessison.getAttribute("username"))
		  sessison.removeAttribute("username");
		
		return "admin/login";
	}
}
